#!/usr/bin python
# -*- coding: utf-8 -*-
# author: denghong

from bs4 import BeautifulSoup
# from BeautifulSoup import BeautifulSoup
import requests
import shutil

url = r'https://mp.weixin.qq.com/s?__biz=MjM5ODE1NDYyMA==&mid=2653384218&idx=1&sn=e2e2ea2d206487b3144968055cc89f05&pass_ticket=lyJNMBhiTzVK4f3Yr8CVUfGHqjey53XtCcIDq3j0WsjA8jyfOghkpSNd1%2FJiDaKA'
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text)
images = soup.findAll("img", attrs={"data-src": True})
idx = 1
succs = 0
dir_path = "./pics"
for img in images:
    url = img["data-src"]
    r = requests.get(url, stream = True)
    if r.status_code == 200:
        file_path = "%s/%d.jpg"%(dir_path, idx)
        with open(file_path, 'wb') as f:
            r.raw.decode_content = True
            shutil.copyfileobj(r.raw, f)
            print("%s -> %s successful" % (url, file_path))
            succs += 1
    idx += 1

print("files: %d success: %d"%(idx, succs))